_package("alz.mui");

_import("alz.mui.ActionElement");

/**
 * 超链接实现的按钮组件
 * var btn = new LinkButton();
 * btn.bind($E("btn1"));
 * //btn.addEventListener("mousedown", this, false);
 * btn.onXXX = function(){this._self};
 */
_class("LinkButton", ActionElement, function(){
	this._init = function(){
		_super._init.call(this);
	};
	this.bind = function(obj, conf){  //{parent,id}
		//this.setParent(conf.parent);
		//this.setParent(obj.parentNode);
		this.init(obj);
	};
	this.init = function(obj){
		_super.init.apply(this, arguments);
		this.addListener(this._self, "tapstart", this, "onTapStart");
		this.addListener(this._self, "tapcancel", this, "onTapCancel");
		if(this._self.type != "submit"){
			this.addListener(this._self, "tap", this, "onTap");
		}
	};
	this.dispose = function(){
		if(this._self.type != "submit"){
			this.removeListener(this._self, "tap");
		}
		this.removeListener(this._self, "tapcancel");
		this.removeListener(this._self, "tapstart");
		_super.dispose.apply(this);
	};
	this.setDisabled = function(v){
		_super.setDisabled.apply(this, arguments);
		/*
		if(this._self){
			this._self.className = this._self.className.replace(/ hov$/g, "") + " hov";
		}
		*/
	};
	this.setState = function(v){
		switch(v){
		case "active":
			runtime._element.addClass(this._self, "hov");
			break;
		case "normal":
		default:
			runtime._element.removeClass(this._self, "hov");
			break;
		}
	};
	this.onTapStart = function(ev){
		if(this._disabled) return;
		this.setState("active");
	};
	this.onTapCancel = function(ev){
		if(this._disabled) return;
		this.setState("normal");
	};
	this.onTap = function(ev){
		if(this._disabled) return;
		//this.onclick();
		var ret = this.dispatchAction(this._self, ev);
		this.setState("normal");
		return ret;
	};
});